
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<title>Madhouse|monitor core</title>
<link rel="stylesheet" href="../assets/css/bootstrap-spacelab.css" />
<link rel="stylesheet" href="../assets/css/base.css?t=20130516173114" />
<link rel="stylesheet" href="../assets/css/validationEngine.jquery.css" type="text/css"/>
  <!-- template
    ================================================== -->
    <script id="t_a" type="text/html">
         <form class="form-horizontal" id="form" onsubmit="return false;">
             <fieldset>
                 <legend>
                     	 修改监控系统的全局事件设置
                 </legend>
                 <div class="control-group">
                     <h5>心跳请求超时秒数</h5>
                     <div class="input-append">
                         <label class="checkbox inline">
                             	超时秒数：
                         </label>
                         <input type="text"  class="validate[required,custom[integer1]] text-input" name="keepAliveOvertimeSec" value="<%= keepAliveOvertimeSec %>" /><span class="add-on">秒</span>
                     </div>
                 </div>
				 				 
                 <%	
				 	 var item ;
				 	 for (i in json) { item = json[i]; 
					%>
                 <div class="control-group">
                     <h5><%= item[2] %></h5>
                     <div class="input-append">
                         <label class="checkbox inline">
                             	黄色警报下限：
                         </label>
                         <input type="text"  class="validate[required,custom[integer1]] text-input" name="<%= i + '-caution' %>" value="<%= item[0] %>" /><span class="add-on"><%= item[3] %></span>
                     </div>
                     <div class="input-append">
                         <label class="checkbox inline">
                             	红色警报下限：
                         </label>
                         <input type="text" class="validate[required,custom[integer1]] text-input" name="<%= i + '-warning' %>" value="<%= item[1] %>" /><span class="add-on"><%= item[3]%></span>
                     </div>
                 </div>
                 <% } %>
             </fieldset>
             <div class="form-actions">
                 <button class='btn btn-info' name="submit">
                     	保存 
                 </button>
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 <button class='btn' name="reset">
                   		  重置 
                 </button>
             </div>
         </form>
			
    </script>

	
<style>
.control-group {
    padding-bottom: 10px;
    border-bottom: solid 1px #eee;
}

.control-group h5 {
    margin-bottom: 10px;
}

.input-append {
    width: 360px;
}

.input-append label {
    width: 100px;
}

.input-append input {
    width: 100px;
}
.input-prepend .add-on, .input-append .add-on{
	width:30px;
}

.form-horizontal .form-actions {
padding-left: 20px;
}
#form .control-group:last-child{
	border:none;
}
</style>

</head>
<body>
    <header>
        <h1><span id="title">事件设置</span></h1>
        <div class="row" id="toolbar">
                <div class="box_1">
                    <button class="btn" id="info" data-toggle="modal" data-target="#modal"  data-keyboard="true" data-backdrop="true">
                        <i class="icon-info-sign"></i> 信息
                    </button>					
                </div>
				
                <div class="btn-group" style="display:none;">
                    <button class="btn">
                        	操作
                    </button>
                    <button class="btn dropdown-toggle" data-toggle="dropdown">
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="#" id="notification"></a></li>
                    </ul>
                </div>
        </div>
    </header>	
	
    <div id="mainbody">
    	<div id="item_1"></div>
        <div id="set_form">
        </div>
    </div>
	

  <!-- 弹出对话框
    ================================================== -->
<div class="modal fade" id="modal">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>help</h3>
  </div>
  <div class="modal-body">
  	nothing.
  </div>
  <div class="modal-footer">
    <a href="#" class="btn"  data-dismiss="modal">关闭</a>
  </div>
</div>


  <!-- js part
    ================================================== -->
<script src="../assets/js/library/jquery-1.7.1.js"></script>
<script src="../assets/js/library/bootstrap.min.js"></script>
<script src="../assets/js/library/template.js"></script>
<script src="../assets/js/library/jquery.validationEngine-en.js"></script>
<script src="../assets/js/library/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/js/helper.js?t=20130516173114"></script>
<script src="../assets/js/doc.js?t=20130516173114"></script>	
<script>
$(function(){
	
	var smartMad = window.smartMad = window.smartMad || {};
	
	////////////////////////////////////////////////////
	//常规选项设置
	////////////////////////////////////////////////////
	var formConf = {
		url: smartMad._url + smartMad.api.getEventSet
	};	
	var formCall = function(e,json){
		var $th = $(this), data, html;
		
		//$th.html(JSON.stringify(json));return;
        ///////////////////////////////////////////////
		
		smartMad.eventJson = json;
		
        data = {
            json: json,
			keepAliveOvertimeSec: smartMad.keepAliveOvertimeSec
        };
        
        ///////////////////////////////////////////////
        
        html = template('t_a', data);
        $th.html(html);
		
		$('#form').validationEngine();
		
	};	
	
	
	////////////////////////////////////////////////////////
	//提交保存
	////////////////////////////////////////////////////////
    $('#mainbody')
	.delegate('button[name="submit"]', 'click', function(){
		//表单验证
		if(!$('#form').validationEngine('validate')){
			return;
		}
		
        var conf = {
			url: smartMad._url + smartMad.api.updateEventSet
        };
		var data = {};
		
		var eventJson = smartMad.eventJson;
		
		for(var i in eventJson){
			data[i] = $('input[name="' + i + '-caution"]').val() + '|' + $('input[name="' + i + '-warning"]').val();
		}
		
		data.keepAliveOvertimeSec = $('input[name="keepAliveOvertimeSec"]').val();
        conf.data = data;	
		
        $(this).postData(conf);
    })
	.delegate('button[name="reset"]', 'click', function(){
		//$('#set_form').getData(formConf);
	});
    
	////////////////////////////////////////////////////////
	//init
	////////////////////////////////////////////////////////
	
	$('#set_form').bind('ajax.success', formCall);
	
	$('#item_1')
	.bind('ajax.success', function(e,json){
		var $th = $(this), data, html;
		
		//$th.html(JSON.stringify(json));return;
		///////////////////////////////////////////////////
		
		smartMad.keepAliveOvertimeSec = json;
		
		$th.hide();
		
		$('#set_form').getData(formConf);
	})
	.getData({
		url: smartMad._url + smartMad.api.getEventKeepaliveSet
	});
	
	
});
</script>
</body>
</html>
